function trim(str) {
  const reg = /^\s+|\s+$/g;
  return str.replace(reg, "");
}

console.log(trim("  aaa "));
console.log(trim("  aaa  bbb  "));
